package com.lsy.weizhi2.picture;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.BaseBundle;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;

import com.lsy.weizhi2.mybase.BaseApp;


/**
 * Created by mayongge on 16/4/19.
 */
public class PictureUtils {
    private static final String TAG = "PictureUtils";

    public static final String OPERATION = "operation";
    public static final int CAMERA = 2; //拍照
    public static final int ALBUM = 1;  //从相册选择图片
    public static final int PREVIEW_IMAGE = 1; //预览图片


    private static IWxCallback mCallback;

    public static void getPictureFromAlbum(Activity activity, IWxCallback callback){
        mCallback = callback;
        Intent intent = new Intent(activity, PictureActivity.class);
        intent.putExtra(OPERATION, ALBUM);
        activity.startActivity(intent);
    }
    public static void PreviewImage(Activity activity){
            if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
                if (activity.checkSelfPermission(Manifest.permission.CAMERA)
                        != PackageManager.PERMISSION_GRANTED) {
                    //请求权限
                    ActivityCompat.requestPermissions(activity,
                            new String[]{Manifest.permission.CAMERA}, CAMERA);
                    //判断是否需要 向用户解释，为什么要申请该权限
                    ActivityCompat.shouldShowRequestPermissionRationale(activity,Manifest.permission.READ_CONTACTS);
                } else {
                    activity.startActivityForResult(
                            new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA);
                }

            }else{
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                activity.startActivityForResult(intent,CAMERA);

            }
    }

    public static IWxCallback getCallback(){
        return mCallback;
    }


}
